<?php
function wrap_sign(&$arr)
{
	$code = chr(rand(65,90)).chr(rand(65,90));
	$arr['time'] = time();
	$arr['code'] = $code;
	ksort($arr);
	$arr['sign'] = sha1($code.md5(http_build_query($arr)).$code);
}
function unwrap_sign(&$arr)
{
	ksort($arr);
	$code = $arr['code'];
	$sign = $arr['sign'];
	unset($arr['sign']);
	if($sign !== sha1($code.md5(http_build_query($arr)).$code))
	{
		throw new Exception("Sign error..");
	}
	if($arr['time'] + 10 * 60 < time())
	{
		throw new Exception("Time over..");
	}
	unset($arr['code'], $arr['time']);
}